<template>
	<view class="content">
		<view class="group">
			<!-- <view class="list" @click="getChange">
				<view class="listname">手机号修改</view>
				<view class="list_fr">
					<view class="txt">{{replaceStr(users.phone,3,4)}}</view>
					<view class="iconfont icon">&#xe601;</view>
				</view>
			</view> -->
			<!-- #ifdef APP-PLUS -->
			<!-- <view class="list">
				<view class="listname">消息推送</view>
				<view class="list_fr">
					<switch @change="switch2Change" class="switch" color="#E42221" :checked="checked"/>
				</view>
			</view> -->
			<!-- #endif -->
			<view class="list" @click="proctol(1)">
				<view class="listname">用户协议</view>
				<view class="list_fr">
					<view class="iconfont icon">&#xe601;</view>
				</view>
			</view>
			<view class="list" @click="proctol(2)">
				<view class="listname">隐私协议</view>
				<view class="list_fr">
					<view class="iconfont icon">&#xe601;</view>
				</view>
			</view>
		</view>
		<view class="logon" @click="logon">
			<view class="list">
				<view class="listname">退出登录</view>
				<view class="list_fr">
					<view class="iconfont icon">&#xe601;</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				users:{},
				userInfo:{},
				isPush:0
				
			}
		},
		onLoad() {
			let that = this;
			uni.$on('login',function(data){
				that.cacheHelper.isLogin()
				that.cacheHelper.updateUserInfo()
				that.getUserInfo();
			})
			// if (that.cacheHelper.isLogin()) {
			// 	that.getUserInfo()
			// } else {
			// 	uni.navigateTo({
			// 		url: '../../login/login',
			// 	});
			// }
		},
		computed:{
			checked: function () {
				let checkedValue;
				if (this.isPush == 0) {
					checkedValue = false
				} else if (this.isPush == 1) {
					checkedValue = true
				}
				return checkedValue;
			}
		},
		methods: {
			// 切换
			switch2Change: function (e) {
				let that = this;
				console.log(e)
				let value = e.detail.value;
				console.log(value)
				if (value == false) {
					that.isPush = 0;
				} else if (value == true) {
					that.isPush = 1
				}
				that.api.changeUsewrInfo({
					isPush:that.isPush
				}).then(res => {
					console.log(res)
					that.tui.toast(res.data)
					setTimeout(function () {
						uni.$emit('login',{msg:'更新信息'})
					},500)
				})
				
			},
			// 获取我的信息
			getUserInfo: function () {
				this.api.getUserInfo().then(res => {
					console.log(res)
					this.users = res.data;
					this.isPush = res.data.isPush;
					this.userInfo = res.data.yxUserinfo;
				})
			},
			// 退出登录
			logon: function () {
				let that = this;
				uni.showModal({
					content: '确定退出登录吗？',
					cancelText: '取消',
					confirmText: '确认',
					success: res => {
						console.log(res)
						if (res.confirm) {
							// this.tui.toast('退出成功');    
							// this.cacheHelper.setToken('');
							uni.navigateTo({
								url:"../../login/login"
							})
							setTimeout(function () {
								// uni.$emit('login', {msg: '用户信息更新'})
								// that.cacheHelper.updateUserInfo()
							},500)
						}
						
					},
					fail: () => {},
					complete: () => {}
				});
			},
			
			// 协议
			proctol: function (type) {
				uni.navigateTo({
					url: '../../login/potocol/potocol?type=' + type,
				});
			},
			// 修改手机号、
			getChange: function () {
				uni.navigateTo({
					url:'changePhone/changePhone'
				});
			}
			
			
			
		}
	}
</script>

<style lang="less">
	page {
		width: 100%;
		box-sizing: border-box;
		letter-spacing: 3rpx;
		background: #F5F5F5;
		font-size: 30rpx;
		color: #140005;
		padding: 20rpx 0;
		
	}
	.content {
		width: 100%;
		box-sizing: border-box;
	}
	.group {
		width: 100%;
		box-sizing: border-box;
		background: #FFFFFF;
		.list {
			width: 100%;
			box-sizing: border-box;
			padding: 10rpx 20rpx;
			line-height: 80rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-bottom: 2rpx solid #F5F5F5;
			.list_fr {
				display: flex;
				justify-content: flex-end;
				align-items: center;
				font-size: 28rpx;
				color: #666666;
				.icon {
					font-size: 26rpx;
					color: #D1D1D1;
					padding-left: 15rpx;
				}
				.switch {
					transform: scale(0.7);
				}
			}
		}
		
		
	}
	.logon {
		width: 100%;
		box-sizing: border-box;
		margin-top: 20rpx;
		background: #FFFFFF;
		.list {
			width: 100%;
			box-sizing: border-box;
			padding: 10rpx 20rpx;
			line-height: 80rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			.list_fr {
				display: flex;
				justify-content: flex-end;
				align-items: center;
				font-size: 28rpx;
				color: #666666;
				.icon {
					font-size: 26rpx;
					color: #D1D1D1;
					padding-left: 15rpx;
				}
				
			}
		}
		
	}
	

</style>
